home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume21 / cloops / part02 < prev    next >
Encoding:
Text File  |  1991-07-25  |  31.7 KB  |  1,016 lines

  1. Newsgroups: comp.sources.misc
  2. From: Martin Fouts <fouts@clipper.ingr.com>
  3. Subject:  v21i037:  cloops - Livermore Loops in C, Part02/03
  4. Message-ID: <1991Jul25.020719.28313@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: cc07cf600ac399272ffcdec1003d37b6
  6. Date: Thu, 25 Jul 1991 02:07:19 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: Martin Fouts <fouts@clipper.ingr.com>
  10. Posting-number: Volume 21, Issue 37
  11. Archive-name: cloops/part02
  12. Environment: Cray2, Alliant Convex Amdahl, Sun, SGI  
  13.  
  14. -----     cut here for Part02
  15. #! /bin/sh
  16. # This is a shell archive.  Remove anything before this line, then unpack
  17. # it by saving it into a file and typing "sh file".  To overwrite existing
  18. # files, type "sh file -c".  You can also feed this as standard input via
  19. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  20. # will see the following message at the end:
  21. #        "End of archive 2 (of 3)."
  22. # Contents:  COPYING baseline.c kernel.c
  23. # Wrapped by fouts@bozeman on Sun Jul 21 18:23:20 1991
  24. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  25. if test -f 'COPYING' -a "${1}" != "-c" ; then 
  26.   echo shar: Will not clobber existing file \"'COPYING'\"
  27. else
  28. echo shar: Extracting \"'COPYING'\" \(12488 characters\)
  29. sed "s/^X//" >'COPYING' <<'END_OF_FILE'
  30. X
  31. X            GNU GENERAL PUBLIC LICENSE
  32. X             Version 1, February 1989
  33. X
  34. X Copyright (C) 1989 Free Software Foundation, Inc.
  35. X                    675 Mass Ave, Cambridge, MA 02139, USA
  36. X Everyone is permitted to copy and distribute verbatim copies
  37. X of this license document, but changing it is not allowed.
  38. X
  39. X                Preamble
  40. X
  41. X  The license agreements of most software companies try to keep users
  42. Xat the mercy of those companies.  By contrast, our General Public
  43. XLicense is intended to guarantee your freedom to share and change free
  44. Xsoftware--to make sure the software is free for all its users.  The
  45. XGeneral Public License applies to the Free Software Foundation's
  46. Xsoftware and to any other program whose authors commit to using it.
  47. XYou can use it for your programs, too.
  48. X
  49. X  When we speak of free software, we are referring to freedom, not
  50. Xprice.  Specifically, the General Public License is designed to make
  51. Xsure that you have the freedom to give away or sell copies of free
  52. Xsoftware, that you receive source code or can get it if you want it,
  53. Xthat you can change the software or use pieces of it in new free
  54. Xprograms; and that you know you can do these things.
  55. X
  56. X  To protect your rights, we need to make restrictions that forbid
  57. Xanyone to deny you these rights or to ask you to surrender the rights.
  58. XThese restrictions translate to certain responsibilities for you if you
  59. Xdistribute copies of the software, or if you modify it.
  60. X
  61. X  For example, if you distribute copies of a such a program, whether
  62. Xgratis or for a fee, you must give the recipients all the rights that
  63. Xyou have.  You must make sure that they, too, receive or can get the
  64. Xsource code.  And you must tell them their rights.
  65. X
  66. X  We protect your rights with two steps: (1) copyright the software, and
  67. X(2) offer you this license which gives you legal permission to copy,
  68. Xdistribute and/or modify the software.
  69. X
  70. X  Also, for each author's protection and ours, we want to make certain
  71. Xthat everyone understands that there is no warranty for this free
  72. Xsoftware.  If the software is modified by someone else and passed on, we
  73. Xwant its recipients to know that what they have is not the original, so
  74. Xthat any problems introduced by others will not reflect on the original
  75. Xauthors' reputations.
  76. X
  77. X  The precise terms and conditions for copying, distribution and
  78. Xmodification follow.
  79. X
  80. X            GNU GENERAL PUBLIC LICENSE
  81. X   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  82. X
  83. X  0. This License Agreement applies to any program or other work which
  84. Xcontains a notice placed by the copyright holder saying it may be
  85. Xdistributed under the terms of this General Public License.  The
  86. X"Program", below, refers to any such program or work, and a "work based
  87. Xon the Program" means either the Program or any work containing the
  88. XProgram or a portion of it, either verbatim or with modifications.  Each
  89. Xlicensee is addressed as "you".
  90. X
  91. X  1. You may copy and distribute verbatim copies of the Program's source
  92. Xcode as you receive it, in any medium, provided that you conspicuously and
  93. Xappropriately publish on each copy an appropriate copyright notice and
  94. Xdisclaimer of warranty; keep intact all the notices that refer to this
  95. XGeneral Public License and to the absence of any warranty; and give any
  96. Xother recipients of the Program a copy of this General Public License
  97. Xalong with the Program.  You may charge a fee for the physical act of
  98. Xtransferring a copy.
  99. X
  100. X  2. You may modify your copy or copies of the Program or any portion of
  101. Xit, and copy and distribute such modifications under the terms of Paragraph
  102. X1 above, provided that you also do the following:
  103. X
  104. X    a) cause the modified files to carry prominent notices stating that
  105. X    you changed the files and the date of any change; and
  106. X
  107. X    b) cause the whole of any work that you distribute or publish, that
  108. X    in whole or in part contains the Program or any part thereof, either
  109. X    with or without modifications, to be licensed at no charge to all
  110. X    third parties under the terms of this General Public License (except
  111. X    that you may choose to grant warranty protection to some or all
  112. X    third parties, at your option).
  113. X
  114. X    c) If the modified program normally reads commands interactively when
  115. X    run, you must cause it, when started running for such interactive use
  116. X    in the simplest and most usual way, to print or display an
  117. X    announcement including an appropriate copyright notice and a notice
  118. X    that there is no warranty (or else, saying that you provide a
  119. X    warranty) and that users may redistribute the program under these
  120. X    conditions, and telling the user how to view a copy of this General
  121. X    Public License.
  122. X
  123. X    d) You may charge a fee for the physical act of transferring a
  124. X    copy, and you may at your option offer warranty protection in
  125. X    exchange for a fee.
  126. X
  127. XMere aggregation of another independent work with the Program (or its
  128. Xderivative) on a volume of a storage or distribution medium does not bring
  129. Xthe other work under the scope of these terms.
  130. X
  131. X  3. You may copy and distribute the Program (or a portion or derivative of
  132. Xit, under Paragraph 2) in object code or executable form under the terms of
  133. XParagraphs 1 and 2 above provided that you also do one of the following:
  134. X
  135. X    a) accompany it with the complete corresponding machine-readable
  136. X    source code, which must be distributed under the terms of
  137. X    Paragraphs 1 and 2 above; or,
  138. X
  139. X    b) accompany it with a written offer, valid for at least three
  140. X    years, to give any third party free (except for a nominal charge
  141. X    for the cost of distribution) a complete machine-readable copy of the
  142. X    corresponding source code, to be distributed under the terms of
  143. X    Paragraphs 1 and 2 above; or,
  144. X
  145. X    c) accompany it with the information you received as to where the
  146. X    corresponding source code may be obtained.  (This alternative is
  147. X    allowed only for noncommercial distribution and only if you
  148. X    received the program in object code or executable form alone.)
  149. X
  150. XSource code for a work means the preferred form of the work for making
  151. Xmodifications to it.  For an executable file, complete source code means
  152. Xall the source code for all modules it contains; but, as a special
  153. Xexception, it need not include source code for modules which are standard
  154. Xlibraries that accompany the operating system on which the executable
  155. Xfile runs, or for standard header files or definitions files that
  156. Xaccompany that operating system.
  157. X
  158. X  4. You may not copy, modify, sublicense, distribute or transfer the
  159. XProgram except as expressly provided under this General Public License.
  160. XAny attempt otherwise to copy, modify, sublicense, distribute or transfer
  161. Xthe Program is void, and will automatically terminate your rights to use
  162. Xthe Program under this License.  However, parties who have received
  163. Xcopies, or rights to use copies, from you under this General Public
  164. XLicense will not have their licenses terminated so long as such parties
  165. Xremain in full compliance.
  166. X
  167. X  5. By copying, distributing or modifying the Program (or any work based
  168. Xon the Program) you indicate your acceptance of this license to do so,
  169. Xand all its terms and conditions.
  170. X
  171. X  6. Each time you redistribute the Program (or any work based on the
  172. XProgram), the recipient automatically receives a license from the original
  173. Xlicensor to copy, distribute or modify the Program subject to these
  174. Xterms and conditions.  You may not impose any further restrictions on the
  175. Xrecipients' exercise of the rights granted herein.
  176. X
  177. X  7. The Free Software Foundation may publish revised and/or new versions
  178. Xof the General Public License from time to time.  Such new versions will
  179. Xbe similar in spirit to the present version, but may differ in detail to
  180. Xaddress new problems or concerns.
  181. X
  182. XEach version is given a distinguishing version number.  If the Program
  183. Xspecifies a version number of the license which applies to it and "any
  184. Xlater version", you have the option of following the terms and conditions
  185. Xeither of that version or of any later version published by the Free
  186. XSoftware Foundation.  If the Program does not specify a version number of
  187. Xthe license, you may choose any version ever published by the Free Software
  188. XFoundation.
  189. X
  190. X  8. If you wish to incorporate parts of the Program into other free
  191. Xprograms whose distribution conditions are different, write to the author
  192. Xto ask for permission.  For software which is copyrighted by the Free
  193. XSoftware Foundation, write to the Free Software Foundation; we sometimes
  194. Xmake exceptions for this.  Our decision will be guided by the two goals
  195. Xof preserving the free status of all derivatives of our free software and
  196. Xof promoting the sharing and reuse of software generally.
  197. X
  198. X                NO WARRANTY
  199. X
  200. X  9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
  201. XFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
  202. XOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
  203. XPROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
  204. XOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  205. XMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
  206. XTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
  207. XPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
  208. XREPAIR OR CORRECTION.
  209. X
  210. X  10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
  211. XWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
  212. XREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
  213. XINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
  214. XOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
  215. XTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
  216. XYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
  217. XPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
  218. XPOSSIBILITY OF SUCH DAMAGES.
  219. X
  220. X             END OF TERMS AND CONDITIONS
  221. X
  222. X    Appendix: How to Apply These Terms to Your New Programs
  223. X
  224. X  If you develop a new program, and you want it to be of the greatest
  225. Xpossible use to humanity, the best way to achieve this is to make it
  226. Xfree software which everyone can redistribute and change under these
  227. Xterms.
  228. X
  229. X  To do so, attach the following notices to the program.  It is safest to
  230. Xattach them to the start of each source file to most effectively convey
  231. Xthe exclusion of warranty; and each file should have at least the
  232. X"copyright" line and a pointer to where the full notice is found.
  233. X
  234. X    <one line to give the program's name and a brief idea of what it does.>
  235. X    Copyright (C) 19yy  <name of author>
  236. X
  237. X    This program is free software; you can redistribute it and/or modify
  238. X    it under the terms of the GNU General Public License as published by
  239. X    the Free Software Foundation; either version 1, or (at your option)
  240. X    any later version.
  241. X
  242. X    This program is distributed in the hope that it will be useful,
  243. X    but WITHOUT ANY WARRANTY; without even the implied warranty of
  244. X    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  245. X    GNU General Public License for more details.
  246. X
  247. X    You should have received a copy of the GNU General Public License
  248. X    along with this program; if not, write to the Free Software
  249. X    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  250. X
  251. XAlso add information on how to contact you by electronic and paper mail.
  252. X
  253. XIf the program is interactive, make it output a short notice like this
  254. Xwhen it starts in an interactive mode:
  255. X
  256. X    Gnomovision version 69, Copyright (C) 19xx name of author
  257. X    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
  258. X    This is free software, and you are welcome to redistribute it
  259. X    under certain conditions; type `show c' for details.
  260. X
  261. XThe hypothetical commands `show w' and `show c' should show the
  262. Xappropriate parts of the General Public License.  Of course, the
  263. Xcommands you use may be called something other than `show w' and `show
  264. Xc'; they could even be mouse-clicks or menu items--whatever suits your
  265. Xprogram.
  266. X
  267. XYou should also get your employer (if you work as a programmer) or your
  268. Xschool, if any, to sign a "copyright disclaimer" for the program, if
  269. Xnecessary.  Here a sample; alter the names:
  270. X
  271. X  Yoyodyne, Inc., hereby disclaims all copyright interest in the
  272. X  program `Gnomovision' (a program to direct compilers to make passes
  273. X  at assemblers) written by James Hacker.
  274. X
  275. X  <signature of Ty Coon>, 1 April 1989
  276. X  Ty Coon, President of Vice
  277. X
  278. XThat's all there is to it!
  279. END_OF_FILE
  280. if test 12488 -ne `wc -c <'COPYING'`; then
  281.     echo shar: \"'COPYING'\" unpacked with wrong size!
  282. fi
  283. # end of 'COPYING'
  284. fi
  285. if test -f 'baseline.c' -a "${1}" != "-c" ; then 
  286.   echo shar: Will not clobber existing file \"'baseline.c'\"
  287. else
  288. echo shar: Extracting \"'baseline.c'\" \(4776 characters\)
  289. sed "s/^X//" >'baseline.c' <<'END_OF_FILE'
  290. X/*
  291. X * This file is part of the Livermore Loops transliteration into C.
  292. X * Copyright (C) 1991 by Martin Fouts
  293. X *
  294. X * This program is free software; you can redistribute it and/or modify
  295. X * it under the terms of the GNU General Public License as published by
  296. X * the Free Software Foundation; either version 1, or (at your option)
  297. X * any later version.
  298. X *
  299. X * This program is distributed in the hope that it will be useful,
  300. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  301. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  302. X * GNU General Public License for more details.
  303. X *
  304. X * You should have received a copy of the GNU General Public License
  305. X * along with this program; if not, write to the Free Software
  306. X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  307. X */
  308. X
  309. X#include <stdio.h>
  310. X
  311. X#define BASENAME "baseline.dat"
  312. X#define NTESTS 24
  313. X
  314. X#define TRUE 1
  315. X#define FALSE 0
  316. X
  317. X#define PERCENT 0.05
  318. X
  319. X#define abs(a) (((a) < 0) ? -(a) : (a))
  320. X
  321. XFILE *fopen();
  322. Xchar *fgets();
  323. X
  324. Xdouble err(a,b)
  325. Xdouble a, b;
  326. X{
  327. X  if (a == 0.0) {
  328. X    return(b);
  329. X  } else {
  330. X    return(abs(b-a)/a);
  331. X  }
  332. X}
  333. X
  334. Xmain(argc,argv)
  335. Xint argc;
  336. Xchar *argv[];
  337. X{
  338. X  int i;
  339. X  int errors;
  340. X  char *basename, *testname;
  341. X  FILE *baseline, *testdata;
  342. X  int kern, span;
  343. X  double percent = PERCENT;
  344. X  double flops, weight, sum;
  345. X  int b_kern, b_flag[NTESTS];
  346. X  int b_span[NTESTS];
  347. X  double b_flops[NTESTS], b_weight[NTESTS], b_sum[NTESTS];
  348. X  int t_kern, t_flag[NTESTS];
  349. X  int t_span[NTESTS];
  350. X  double t_flops[NTESTS], t_weight[NTESTS], t_sum[NTESTS];
  351. X  double dummy, worst;
  352. X  char buffer[BUFSIZ];
  353. X
  354. X  if (argc == 2) {
  355. X    basename = BASENAME;
  356. X    testname = argv[1];
  357. X  } else {
  358. X    if (argc == 3) {
  359. X      basename = BASENAME;
  360. X      sscanf(argv[2],"%f",&percent);
  361. X      printf("Using percent = %f\n", percent);
  362. X      testname = argv[1];
  363. X    } else {
  364. X      if (argc == 4) {
  365. X    basename = argv[3];
  366. X    sscanf(argv[2],"%f",&percent);
  367. X    testname = argv[1];
  368. X      } else {
  369. X    fprintf(stderr,"Usage: %s testname [percent [basename]]\n", argv[0]);
  370. X      }
  371. X    }
  372. X  }
  373. X
  374. X  if ((baseline = fopen(basename,"r")) == NULL) {
  375. X    fprintf(stderr,"Error attempting to open %s", basename);
  376. X    perror("");
  377. X    exit(1);
  378. X  }
  379. X
  380. X  if ((testdata = fopen(testname,"r")) == NULL) {
  381. X    fprintf(stderr,"Error attempting to open %s", testname);
  382. X    perror("");
  383. X    exit(1);
  384. X  }
  385. X
  386. X  for (i = 0; i < NTESTS; i++) {
  387. X    b_flag[i] = FALSE;
  388. X    t_flag[i] = FALSE;
  389. X  }
  390. X
  391. X  while (fgets(buffer,BUFSIZ,baseline) != NULL) {
  392. X    sscanf(buffer,"%d %e %e %e %d %e %e\n", &kern, &flops, &dummy,
  393. X       &dummy, &span, &weight, &sum);
  394. X    if ((kern < 1) || (kern > NTESTS)) {
  395. X      fprintf(stderr,"Ignoring data from baseline:\n");
  396. X      fprintf(stderr,"%s\n", buffer);
  397. X    }
  398. X    b_kern = kern - 1;
  399. X    b_flag[b_kern] = TRUE;
  400. X    b_span[b_kern] = span;
  401. X    b_flops[b_kern] = flops;
  402. X    b_weight[b_kern] = weight;
  403. X    b_sum[b_kern] = sum;
  404. X  }
  405. X
  406. X  while (fgets(buffer,BUFSIZ,testdata) != NULL) {
  407. X    sscanf(buffer,"%d %e %e %e %d %e %e\n", &kern, &flops, &dummy,
  408. X       &dummy, &span, &weight, &sum);
  409. X    if ((kern < 1) || (kern > NTESTS)) {
  410. X      fprintf(stderr,"Ignoring data from baseline:\n");
  411. X      fprintf(stderr,"%s\n", buffer);
  412. X    }
  413. X    t_kern = kern - 1;
  414. X    t_flag[t_kern] = TRUE;
  415. X    t_span[t_kern] = span;
  416. X    t_flops[t_kern] = flops;
  417. X    t_weight[t_kern] = weight;
  418. X    t_sum[t_kern] = sum;
  419. X  }
  420. X
  421. X  for (i = 0; i < NTESTS; i++) {
  422. X    if (!b_flag[i]) {
  423. X      if (t_flag[i]) {
  424. X    fprintf(stdout,"Kernel %d: No baseline.  Test data.\n",i+1);
  425. X      } else {
  426. X    fprintf(stdout,"Kernel %d: No baseline.  No test data.\n",i+1);
  427. X      }
  428. X    } else {
  429. X      if (!t_flag[i]) {
  430. X    fprintf(stdout,"Kernel %d: Baseline.  No test data.\n",i+1);
  431. X      } else {
  432. X
  433. X    errors = 0;
  434. X    worst = 0.0;
  435. X
  436. X    dummy = err(b_flops[i],t_flops[i]);
  437. X    if (dummy > percent) {
  438. X      fprintf(stdout,"Kernel %d: Flops:  baseline = %g, test = %g\n",
  439. X          i+1, b_flops[i], t_flops[i]);
  440. X      errors++;
  441. X    }
  442. X    if (dummy > worst) worst = dummy;
  443. X
  444. X    dummy = err((double)b_span[i],(double)t_span[i]);
  445. X    if (dummy > percent) {
  446. X      fprintf(stdout,"Kernel %d: Span:  baseline = %d, test = %d\n",
  447. X          i+1, b_span[i], t_span[i]);
  448. X      errors++;
  449. X    }
  450. X    if (dummy > worst) worst = dummy;
  451. X
  452. X    dummy = err(b_weight[i],t_weight[i]);
  453. X    if (dummy > percent) {
  454. X      fprintf(stdout,"Kernel %d: Weight:  baseline = %g, test = %g\n",
  455. X          i+1, b_weight[i], t_weight[i]);
  456. X      errors++;
  457. X    }
  458. X    if (dummy > worst) worst = dummy;
  459. X
  460. X    dummy = err(b_sum[i],t_sum[i]);
  461. X    if (dummy > percent) {
  462. X      fprintf(stdout,"Kernel %d: Sum:  baseline = %g, test = %g\n",
  463. X          i+1, b_sum[i], t_sum[i]);
  464. X      errors++;
  465. X    }
  466. X    if (dummy > worst) worst = dummy;
  467. X
  468. X/*
  469. X    if (errors == 0) {
  470. X      fprintf(stdout,"Kernel %d: Baseline and Test agree.\n", i+1);
  471. X    } else {
  472. X      fprintf(stdout,"Kernel %d: Baseline and Test disagree %d times.\n",
  473. X          i+1, errors);
  474. X    }
  475. X*/
  476. X      }
  477. X    }
  478. X  }
  479. X  
  480. X  exit(0);
  481. X}
  482. X
  483. END_OF_FILE
  484. if test 4776 -ne `wc -c <'baseline.c'`; then
  485.     echo shar: \"'baseline.c'\" unpacked with wrong size!
  486. fi
  487. # end of 'baseline.c'
  488. fi
  489. if test -f 'kernel.c' -a "${1}" != "-c" ; then 
  490.   echo shar: Will not clobber existing file \"'kernel.c'\"
  491. else
  492. echo shar: Extracting \"'kernel.c'\" \(11686 characters\)
  493. sed "s/^X//" >'kernel.c' <<'END_OF_FILE'
  494. X/*
  495. X * This file is part of the Livermore Loops transliteration into C.
  496. X * Copyright (C) 1991 by Martin Fouts
  497. X *
  498. X * This program is free software; you can redistribute it and/or modify
  499. X * it under the terms of the GNU General Public License as published by
  500. X * the Free Software Foundation; either version 1, or (at your option)
  501. X * any later version.
  502. X *
  503. X * This program is distributed in the hope that it will be useful,
  504. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  505. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  506. X * GNU General Public License for more details.
  507. X *
  508. X * You should have received a copy of the GNU General Public License
  509. X * along with this program; if not, write to the Free Software
  510. X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  511. X */
  512. X
  513. X#include "types.h"
  514. X#include "externs.h"
  515. X
  516. X#define isign(i,j) ((j < 0) ? -i : i)
  517. X#define mod2n(i,j) (i % j) + (j / 2) - isign((j/2),i)
  518. X
  519. X#define amax1(a,b) ((a < b) ? b : a)
  520. X#define amin1(a,b) ((a > b) ? b : a)
  521. X
  522. X#define TEST(x) if ((DoTest & (1<<(x-1))) == (1<<(x-1)))
  523. X
  524. Xextern long int DoTest;
  525. X
  526. XVoid test();
  527. Xdouble sqrt();
  528. Xdouble exp();
  529. X
  530. XVoid kernel()
  531. X{
  532. X  Int i, l, k, il, ipntp, ipnt, lw, j, nl1, nl2, kx, ky, ip, i1, j1;
  533. X  Int i2, j2, nr, nz;
  534. X  Int ii, lb, j4, ink;
  535. X  Int kn, jn, kb5i;
  536. X  Float xtemp;
  537. X
  538. X  test((Int)0);
  539. X  TEST(1) {
  540. X    for (l = 0; l < lp; l++)
  541. X    for (k = 0; k < n; k++)
  542. X      x[k]= q + y[k]*(r*z[k+10] + t*z[k+11]);
  543. X}
  544. X  test((Int)1);
  545. X  TEST(2) {
  546. X  for (l = 0; l < lp; l++) {
  547. X    il= n;
  548. X    ipntp= 0;
  549. X  l_222:   ipnt= ipntp;
  550. X    ipntp= ipntp+il;
  551. X    il= il/2;
  552. X    i= ipntp;
  553. X    for (k = ipnt+1; k < ipntp; k += 2) {
  554. X      i= i+1;
  555. X      x[i]= x[k] - v[k]*x[k-1] - v[k+1]*x[k+1];
  556. X    }
  557. X    if( il>1) goto l_222;
  558. X  }
  559. X}
  560. X  test((Int)2);
  561. X  TEST(3) {
  562. X  for (l = 0; l < lp; l++) {
  563. X    q = 0.0;
  564. X    for (k = 0; k < n; k++) {
  565. X      q += z[k]*x[k];
  566. X    }
  567. X  }
  568. X}
  569. X  test((Int)3);
  570. X  TEST(4) {
  571. X  m= (1001-7)/2;
  572. X  for (l = 0; l < lp; l++) {
  573. X    for (k = 6; k < 1001; k += m) {
  574. X      lw= k-6;
  575. X      for (j = 4; j < n; j += 5) {
  576. X    x[k-1]= x[k-1] - x[lw]*y[j];
  577. X    lw= lw+1;
  578. X      }
  579. X      x[k-1]= y[4]*x[k-1];
  580. X    }
  581. X  }
  582. X}
  583. X  test((Int)4);
  584. X  TEST(5) {
  585. X  for (l = 0; l < lp; l++)
  586. X    for (i = 1; i < n; i++)
  587. X      x[i]= z[i]*(y[i] - x[i-1]);
  588. X}
  589. X  test((Int)5);
  590. X  TEST(6) {
  591. X  for (l = 0; l < lp; l++)
  592. X    for (i = 1; i < n; i++)
  593. X      for (k = 0; k < i; k++)
  594. X    w[i] += b[i][k] * w[i-k-1];
  595. X}
  596. X  test((Int)6);
  597. X  TEST(7) {
  598. X  for (l = 0; l < lp; l++)
  599. X    for (k = 0; k < n; k++)
  600. X      x[k]=     u[k  ] + r*( z[k  ] + r*y[k  ]) +
  601. X    t*( u[k+3] + r*( u[k+2] + r*u[k+1]) +
  602. X       t*( u[k+6] + r*( u[k+5] + r*u[k+4])));
  603. X}
  604. X  test((Int)7);
  605. X  TEST(8) {
  606. X  for (l = 0; l < lp; l++) {
  607. X    nl1 = 0;
  608. X    nl2 = 1;
  609. X    for (kx = 1; kx < 3; kx++) {
  610. X      for (ky = 1; ky < n; ky++) {
  611. X    du1[ky]= u1[kx][ky+1][nl1] - u1[kx][ky-1][nl1];
  612. X    du2[ky]= u2[kx][ky+1][nl1] - u2[kx][ky-1][nl1];
  613. X    du3[ky]= u3[kx][ky+1][nl1] - u3[kx][ky-1][nl1];
  614. X    u1[kx][ky][nl2]= u1[kx][ky][nl1]+a11*du1[ky]+a12*du2[ky]+a13*du3[ky]+
  615. X      sig*(u1[kx+1][ky][nl1]-2.*u1[kx][ky][nl1]+u1[kx-1][ky][nl1]);
  616. X    u2[kx][ky][nl2]= u2[kx][ky][nl1]+a21*du1[ky]+a22*du2[ky]+a23*du3[ky]+
  617. X      sig*(u2[kx+1][ky][nl1]-2.*u2[kx][ky][nl1]+u2[kx-1][ky][nl1]);
  618. X    u3[kx][ky][nl2]= u3[kx][ky][nl1]+a31*du1[ky]+a32*du2[ky]+a33*du3[ky]+
  619. X      sig*(u3[kx+1][ky][nl1]-2.*u3[kx][ky][nl1]+u3[kx-1][ky][nl1]);
  620. X      }
  621. X    }
  622. X  }
  623. X}
  624. X  test((Int)8);
  625. X  TEST(9) {
  626. X  for (l = 0; l < lp; l++)
  627. X    for (i = 0; i < n; i++)
  628. X      px[ 0][i]= dm28*px[12][i] + dm27*px[11][i] + dm26*px[10][i] +
  629. X    dm25*px[9][i] + dm24*px[8][i] + dm23*px[7][i] +
  630. X      dm22*px[6][i] +  c0*(px[4][i] +      px[5][i])+ px[ 2][i];
  631. X}
  632. X  test((Int)9);
  633. X  TEST(10) {
  634. X  for (l = 0; l < lp; l++) {
  635. X    for (i = 0; i < n; i++) {
  636. X      ar      =      cx[4][i];
  637. X      br      = ar - px[4][i];
  638. X      px[4][i] = ar;
  639. X      cr      = br - px[5][i];
  640. X      px[5][i] = br;
  641. X      ar      = cr - px[6][i];
  642. X      px[6][i] = cr;
  643. X      br      = ar - px[7][i];
  644. X      px[7][i] = ar;
  645. X      cr      = br - px[8][i];
  646. X      px[8][i] = br;
  647. X      ar      = cr - px[9][i];
  648. X      px[9][i]= cr;
  649. X      br      = ar - px[10][i];
  650. X      px[10][i]= ar;
  651. X      cr      = br - px[11][i];
  652. X      px[11][i]= br;
  653. X      px[13][i]= cr - px[12][i];
  654. X      px[12][i]= cr;
  655. X    }
  656. X  }
  657. X}
  658. X  test((Int)10);
  659. X  TEST(11) {
  660. X  for (l = 0; l < lp; l++) {
  661. X    x[0]= y[0];
  662. X    for (k = 1; k < n; k++) {
  663. X      x[k]= x[k-1] + y[k];
  664. X    }
  665. X  }
  666. X}
  667. X  test((Int)11);
  668. X  TEST(12) {
  669. X  for (l = 0; l < lp; l++) {
  670. X    for (k = 0; k < n; k++) {
  671. X      x[k]= y[k+1] - y[k];
  672. X    }
  673. X  }
  674. X}
  675. X  test((Int)12);
  676. X  TEST(13) {
  677. X  for (l = 0; l < lp; l++) {
  678. X    for (ip = 0; ip < n; ip++) {
  679. X      i1= p[0][ip];
  680. X      j1= p[1][ip];
  681. X      i1=        mod2n(i1,64);
  682. X      j1=        mod2n(j1,64);
  683. X      p[2][ip]= p[2][ip]  + b[i1][j1];
  684. X      p[3][ip]= p[3][ip]  + c[i1][j1];
  685. X      p[0][ip]= p[0][ip]  + p[2][ip];
  686. X      p[1][ip]= p[1][ip]  + p[3][ip];
  687. X      i2= p[0][ip];
  688. X      j2= p[1][ip];
  689. X      i2=            mod2n(i2,64) - 1;
  690. X      j2=            mod2n(j2,64) - 1;
  691. X      p[0][ip]= p[0][ip]  + y[i2+32];
  692. X      p[1][ip]= p[1][ip]  + z[j2+32];
  693. X      i2= i2       + e[i2+32];
  694. X      j2= j2       + f[j2+32];
  695. X      h[i2][j2]= h[i2][j2] + 1.0;
  696. X    }
  697. X  }
  698. X}
  699. X  test((Int)13);
  700. X  TEST(14) {
  701. X  for (l = 0; l < lp; l++) {
  702. X    for (k = 0; k < n; k++) {
  703. X      ix[k]= (Int) grd[k];
  704. X      xi[k]= (Float) ix[k];
  705. X      ex1[k]= ex [ ix[k]-1 ];
  706. X      dex1[k]= dex  [ ix[k]-1 ];
  707. X    }
  708. X    for (k = 0; k < n; k++) {
  709. X      vx[k]= vx[k] + ex1[k] + (xx[k] - xi[k])*dex1[k];
  710. X      xx[k]= xx[k] + vx[k]  + flx;
  711. X      ir[k]= xx[k];
  712. X      rx[k]= xx[k] - ir[k];
  713. X      ir[k]= mod2n(  ir[k],512) + 1;
  714. X      xx[k]= rx[k] + ir[k];
  715. X    }
  716. X    for (k = 0; k < n; k++) {
  717. X      rh[ir[k]-1]= rh[ir[k]-1] + 1.0 - rx[k];
  718. X      rh[ir[k]]= rh[ir[k]] + rx[k];
  719. X    }
  720. X  }
  721. X}
  722. X  test((Int)14);
  723. X  TEST(15) {
  724. X  for (l = 0; l < lp; l++) {
  725. X    nr= 7;
  726. X    nz= n;
  727. X    ar= 0.053;
  728. X    br= 0.073;
  729. X    for (j = 1; j < nr; j++) {
  730. X      for (k = 1; k < nz; k++) {
  731. X    if (j >= (nr-1)) {
  732. X      vy[k][j] = 0.0;
  733. X      continue;
  734. X    }
  735. X    if (vh[k][j+1] > vh[k][j]) {
  736. X      t = ar;
  737. X    } else {
  738. X      t = br;
  739. X    }
  740. X    if (vf[k][j] < vf[k-1][j]) {
  741. X          r= amax1(vh[k-1][j], vh[k-1][j+1]);
  742. X          s= vf[k-1][j];
  743. X    } else {
  744. X          r= amax1( vh[k][j],   vh[k][j+1]);
  745. X          s= vf[k][j];
  746. X    }
  747. X        vy[k][j]= sqrt((double) (vg[k][j]*vg[k][j] +r*r))*t/s;
  748. X    if (k >= (nz-1)) {
  749. X        vs[k][j] = 0.;
  750. X        continue;
  751. X    }
  752. X        if (vf[k][j]  < vf[k][j-1]) {
  753. X          r= amax1( vg[k][j-1], vg[k+1][j-1]);
  754. X          s= vf[k][j-1];
  755. X          t= br;
  756. X    } else {
  757. X          r= amax1( vg[k][j],   vg[k+1][j]);
  758. X          s= vf[k][j];
  759. X          t= ar;
  760. X    }
  761. X        vs[k][j]= sqrt((double) (vh[k][j]*vh[k][j] +r*r))*t/s;
  762. X      }
  763. X    }
  764. X  }
  765. X}
  766. X  test((Int)15);
  767. X  TEST(16) {
  768. X  ii= n/3;
  769. X  lb= ii+ii;
  770. X  k2= 0;
  771. X  k3= 0;
  772. X  for (l = 0; l < lp; l++) {
  773. X    m= 0;
  774. X    i1= m;
  775. Xl_410:
  776. X    j2= ((n+n)*m) + 1;
  777. X    for (k = 0; k < n; k++) {
  778. X      k2= k2+1;
  779. X      j4= j2+k+k+1;
  780. X      j5= zone[j4];
  781. X      if (j5-n+1 < 0) goto l_420;
  782. X      if (j5-n+1 == 0) goto l_475;
  783. X      goto l_450;
  784. Xl_415:
  785. X      if (j5-n+ii+1 < 0) goto l_430;
  786. X      if (j5-n+ii+1 == 0) goto l_425;
  787. X      goto l_425;
  788. Xl_420:
  789. X      if (j5-n+lb+1 < 0) goto l_435;
  790. X      if (j5-n+lb+1 == 0) goto l_415;
  791. X      goto l_415;
  792. Xl_425:
  793. X      if (plan[j5] - r < 0) goto l_445;
  794. X      if (plan[j5] - r == 0) goto l_480;
  795. X      goto l_440;
  796. Xl_430:
  797. X      if (plan[j5] - s < 0) goto l_445;
  798. X      if (plan[j5] - s == 0) goto l_480;
  799. X      goto l_440;
  800. Xl_435:
  801. X      if (plan[j5] - t < 0) goto l_445;
  802. X      if (plan[j5] - t == 0) goto l_480;
  803. X      goto l_440;
  804. Xl_440:
  805. X      if (zone[j4-1]+1 < 0) goto l_455;
  806. X      if (zone[j4-1]+1 == 0) goto l_485;
  807. X      goto l_470;
  808. Xl_445:
  809. X      if (zone[j4-1]+1 < 0) goto l_470;
  810. X      if (zone[j4-1]+1 == 0) goto l_485;
  811. X      goto l_455;
  812. Xl_450:
  813. X      k3= k3+1;
  814. X      xtemp = d[j5] - (d[j5-1]*((t-d[j5-2])*(t-d[j5-2])
  815. X                +(s-d[j5-3])*(s-d[j5-3])
  816. X                +(r-d[j5-4])*(r-d[j5-4])));
  817. X      if (xtemp < 0) goto l_445;
  818. X      if (xtemp == 0) goto l_480;
  819. X      goto l_440;
  820. Xl_455:
  821. X      m= m+1;
  822. X      if (m < zone[0]) goto l_465;
  823. X      if (m == zone[0]) goto l_465;
  824. X      goto l_460;
  825. Xl_460:
  826. X      m= 0;
  827. Xl_465:
  828. X      if (i1 - m < 0) goto l_410;
  829. X      if (i1 - m == 0) goto l_480;
  830. X      goto l_410;
  831. Xl_470: ;
  832. X    }
  833. Xl_475:
  834. Xl_480:
  835. Xl_485: ;
  836. X  }
  837. X}
  838. X  test((Int)16);
  839. X  TEST(17) {
  840. X  for (l = 0; l < lp; l++) {
  841. X    i= n-1;
  842. X    j= 0;
  843. X    ink= -1;
  844. X    scale= 5./3.;
  845. X    xnm= 1./3.;
  846. X    e6= 1.03/3.07;
  847. X    goto l_61;
  848. Xl_60:
  849. X    e6= xnm*vsp[i]+vstp[i];
  850. X    vxne[i]= e6;
  851. X    xnm= e6;
  852. X    ve3[i]= e6;
  853. X    i= i+ink;
  854. X    if (i == j) goto  l_62;
  855. Xl_61:
  856. X    e3= xnm*vlr[i] +vlin[i];
  857. X    xnei= vxne[i];
  858. X    vxnd[i]= e6;
  859. X    xnc= scale*e3;
  860. X    if ( xnm >xnc) goto  l_60;
  861. X    if ( xnei>xnc) goto  l_60;
  862. X    ve3[i]= e3;
  863. X    e6= e3+e3-xnm;
  864. X    vxne[i]= e3+e3-xnei;
  865. X    xnm= e6;
  866. X    i= i+ink;
  867. X    if ( i != j) goto l_61;
  868. Xl_62:
  869. X   ;
  870. X  }
  871. X}
  872. X  test((Int)17);
  873. X  TEST(18) {
  874. X  for (l = 0; l < lp; l++) {
  875. X    t= 0.0037;
  876. X    s= 0.0041;
  877. X    kn= 6;
  878. X    jn= n;
  879. X    for (k = 1; k < kn; k++) {
  880. X      for (j = 1; j < jn; j++) {
  881. X    za[j][k]= (zp[j-1][k+1]+zq[j-1][k+1]-zp[j-1][k]-zq[j-1][k])
  882. X      *(zr[j][k]+zr[j-1][k])/(zm[j-1][k]+zm[j-1][k+1]);
  883. X    zb[j][k]= (zp[j-1][k]+zq[j-1][k]-zp[j][k]-zq[j][k])
  884. X      *(zr[j][k]+zr[j][k-1])/(zm[j][k]+zm[j-1][k]);
  885. X      }
  886. X    }
  887. X    for (k = 1; k < kn; k++) {
  888. X      for (j = 1; j < jn; j++) {
  889. X#ifdef CRAY2
  890. X    temp1 =  za[j][k]   *(zz[j][k]-zz[j+1][k]);
  891. X    temp2 = -za[j-1][k] *(zz[j][k]-zz[j-1][k]);
  892. X    temp3 = -zb[j][k]   *(zz[j][k]-zz[j][k-1]);
  893. X    temp4 =  zb[j][k+1] *(zz[j][k]-zz[j][k+1]);
  894. X    zu[j][k] += s*(temp1+temp2+temp3+temp4);
  895. X        temp1 =za[j][k]*(zr[j][k]-zr[j+1][k]);
  896. X    temp2 = -za[j-1][k] *(zr[j][k]-zr[j-1][k]);
  897. X    temp3 = -zb[j][k]   *(zr[j][k]-zr[j][k-1]);
  898. X    temp4 = zb[j][k+1] *(zr[j][k]-zr[j][k+1]);
  899. X        zv[j][k] += s*(temp1+temp2+temp3+temp4);
  900. X#else    
  901. X    zu[j][k]= zu[j][k]+s*(za[j][k]*(zz[j][k]-zz[j+1][k])
  902. X                  -za[j-1][k] *(zz[j][k]-zz[j-1][k])
  903. X                  -zb[j][k]   *(zz[j][k]-zz[j][k-1])
  904. X                  +zb[j][k+1] *(zz[j][k]-zz[j][k+1]));
  905. X    zv[j][k]= zv[j][k]+s*(za[j][k]*(zr[j][k]-zr[j+1][k])
  906. X                  -za[j-1][k] *(zr[j][k]-zr[j-1][k])
  907. X                  -zb[j][k]   *(zr[j][k]-zr[j][k-1])
  908. X                  +zb[j][k+1] *(zr[j][k]-zr[j][k+1]));
  909. X#endif
  910. X      }
  911. X    }
  912. X    for (k = 1; k < kn; k++) {
  913. X      for (j = 1; j < jn; j++) {
  914. X          zr[j][k]= zr[j][k]+t*zu[j][k];
  915. X          zz[j][k]= zz[j][k]+t*zv[j][k];
  916. X    }
  917. X    }
  918. X  }
  919. X}
  920. X  test((Int)18);
  921. X  TEST(19) {
  922. X  kb5i= 0;
  923. X  for (l = 0; l < lp; l++) {
  924. X    for (k = 0; k < n; k++) {
  925. X      b5[k+kb5i]= sa[k] +stb5*sb[k];
  926. X      stb5= b5[k+kb5i] -stb5;
  927. X    }
  928. X    for (i = 0; i < n; i++) {
  929. X      k= n-i+1;
  930. X      b5[k+kb5i]= sa[k] +stb5*sb[k];
  931. X      stb5= b5[k+kb5i] -stb5;
  932. X    }
  933. X  }
  934. X}
  935. X  test((Int)19);
  936. X  TEST(20) {
  937. X  for (l = 0; l < lp; l++) {
  938. X    for (k = 0; k < n; k++) {
  939. X      di= y[k]-g[k]/( xx[k]+dk);
  940. X      dn= 0.2;
  941. X      if ( di != 0.0) dn= amax1( 0.1,amin1( z[k]/di, 0.2));
  942. X      x[k]= ((w[k]+v[k]*dn)* xx[k]+u[k])/(vx[k]+v[k]*dn);
  943. X      xx[k+1]= (x[k]- xx[k])*dn+ xx[k];
  944. X    }
  945. X  }
  946. X}
  947. X  test((Int)20);
  948. X  TEST(21) {
  949. X  for (l = 0; l < lp; l++)
  950. X    for (i = 0; i < n; i++)
  951. X      for (k = 0; k < n; k++)
  952. X    for (j = 0; j < n; j++)
  953. X      px[i][j]= px[i][j] +vy[i][k] * cx[k][j];
  954. X}
  955. X  test((Int)21);
  956. X  TEST(22) {
  957. X  expmax= 20.0;
  958. X  u[n-1]= 0.99*expmax*v[n-1];
  959. X  for (l = 0; l < lp; l++) {
  960. X    for (k = 0; k < n; k++) {
  961. X      y[k]= u[k]/v[k];
  962. X      w[k]= x[k]/( exp((double) y[k]) -1.0);
  963. X    }
  964. X  }
  965. X}
  966. X  test((Int)22);
  967. X  TEST(23) {
  968. X  for (l = 0; l < lp; l++) {
  969. X    for (j = 1; j < 6; j++) {
  970. X      for (k = 1; k < n; k++) {
  971. X    qa= za[k][j+1]*zr[k][j] +za[k][j-1]*zb[k][j] +
  972. X      za[k+1][j]*zu[k][j] +za[k-1][j]*zv[k][j] +zz[k][j];
  973. X    za[k][j]= za[k][j] +.175*(qa -za[k][j]);
  974. X      }
  975. X    }
  976. X  }
  977. X}
  978. X  test((Int)23);
  979. X  TEST(24) {
  980. X  x[ n/2]= -1.0e+10;
  981. X  for (l = 0; l < lp; l++) {
  982. X    m= 1;
  983. X    for (k = 1; k < n; k++) {
  984. X      if ( x[k] < x[m])  m= k;
  985. X    }
  986. X  }
  987. X}
  988. X  test((Int)24);
  989. X  return;
  990. X}
  991. END_OF_FILE
  992. if test 11686 -ne `wc -c <'kernel.c'`; then
  993.     echo shar: \"'kernel.c'\" unpacked with wrong size!
  994. fi
  995. # end of 'kernel.c'
  996. fi
  997. echo shar: End of archive 2 \(of 3\).
  998. cp /dev/null ark2isdone
  999. MISSING=""
  1000. for I in 1 2 3 ; do
  1001.     if test ! -f ark${I}isdone ; then
  1002.     MISSING="${MISSING} ${I}"
  1003.     fi
  1004. done
  1005. if test "${MISSING}" = "" ; then
  1006.     echo You have unpacked all 3 archives.
  1007.     rm -f ark[1-9]isdone
  1008. else
  1009.     echo You still need to unpack the following archives:
  1010.     echo "        " ${MISSING}
  1011. fi
  1012. ##  End of shell archive.
  1013. exit 0
  1014.  
  1015. exit 0 # Just in case...
  1016.